// columns.ts

import DictTag, { DictValueEnum } from "@/components/DictTag";
import IconFont from "@/components/IconFont";
import { createIcon } from "@/utils/IconUtil";
import { ProColumns } from "@ant-design/pro-table";
import { Avatar, Divider, Dropdown, MenuProps, Popconfirm, Space, Switch, Typography } from "antd";

// 定义所有列的工厂函数
export const createTableColumns = (
	visibleOptions: DictValueEnum,
	handleColumnEditor: (record: API.Setting.Menu) => void,
	handleColumnRemove: (record: API.Setting.Menu) => void
): ProColumns<API.Setting.Menu>[] => {
	return [
		{
			title: "菜单名称",
			dataIndex: "menuName",
			valueType: "text"
		},
		{
			title: "所属应用",
			dataIndex: "appName",
			valueType: "text"
			// render: (_, record) => {
			// 	return <>系统应用</>;
			// }
		},
		{
			title: "菜单图标",
			dataIndex: "icon",
			valueType: "text",
			hideInSearch: true,
			render: (_, record) => {
				const icon = record?.icon;
				const iconComponent = icon ? icon.startsWith("icon-") ? <IconFont type={icon} /> : createIcon(icon) : "-";
				return <>{iconComponent} </>;
			}
		},
		{
			title: "路由地址",
			dataIndex: "path",
			valueType: "text",
			ellipsis: true
		},
		{
			title: "显示顺序",
			dataIndex: "sort",
			valueType: "text",
			hideInSearch: true,
			sorter: (a, b) => a?.sort - b?.sort
		},
		// {
		// 	title: "权限标识",
		// 	dataIndex: "perms",
		// 	valueType: "text",
		// 	hideInSearch: true
		// },
		{
			title: "是否可见",
			dataIndex: "visible",
			valueType: "select",
			valueEnum: visibleOptions,
			render: (_, record) => {
				return <DictTag enums={visibleOptions} type="tag" value={record?.visible} />;
			}
		},
		{
			title: "操作",
			dataIndex: "option",
			width: "220px",
			valueType: "option",
			fixed: "right",
			render: (_, record: any) => {
				return (
					record?.id !== 1 && (
						<>
							<Space size={1} split={<Divider type="vertical" />}>
								<Typography.Link
									key="edit"
									onClick={() => {
										handleColumnEditor(record);
									}}
								>
									编辑
								</Typography.Link>
								<Popconfirm
									placement="bottomRight"
									title={"提示"}
									description={`确定删除角色：${record.roleName} 吗？`}
									onConfirm={() => {
										handleColumnRemove(record);
									}}
									okText="确认"
									cancelText="取消"
								>
									<Typography.Link type="danger" key="remove">
										删除
									</Typography.Link>
								</Popconfirm>
							</Space>
						</>
					)
				);
			}
		}
	];
};
const listOperItem: MenuProps["items"] = [
	{
		label: "重置密码",
		key: "restPassword"
	},
	{
		label: "授权角色",
		key: "authRole"
	}
];
export const proTableCardProps = {
	bodyStyle: {
		paddingInline: 0,
		paddingBlock: 0
	}
};

export const pagination = {
	showQuickJumper: true,
	showSizeChanger: true
};

export const formTitle = ["新增菜单", "编辑菜单"];
